home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacFormat España 20
/
macformat_20.iso
/
mac
/
Shareware
/
Desarrolladores
/
Sprite Animation Toolkit 2.3.8
/
Demos
/
StepPlatform Demo ƒ
/
sPlayerSprite.p
< prev
next >
Wrap
Text File
|
1996-05-11
|
4KB
|
180 lines
(* Player sprite for the Platform test *)
unit sPlayerSprite;
interface
uses
{$ifc UNDEFINED THINK_PASCAL}
Types, QuickDraw, Menus, Windows, TextEdit, Fonts,{}
Dialogs, Memory, ToolUtils, Events, {}
{$endc}
SAT, PlatformGlobals;
procedure InitPlayerSprite;
procedure SetupPlayerSprite (me: PlSpritePtr);
procedure HandlePlayerSprite (me: PlSpritePtr);
var
playerSp: PlSpritePtr;
implementation
{ifndef abs}
{abs=(x) (x>0?x:-x);}
{endif}
const
PlayerHigh = 64;
PlayerSpeed = 5;
Gforce = 2;{like g = 9.8 m/sec^2}
JumpSpeed = 23;
var
rightFaces, leftFaces: array[0..4] of FacePtr;
fallFace: array[0..2] of FacePtr;
procedure HandleKeys (me: PlSpritePtr);
forward;
procedure InitPlayerSprite;
var
i: Integer;
begin
for i := 0 to 3 do
begin
leftFaces[i] := SATGetFace(128 + i);
rightFaces[i] := SATGetFace(132 + i);
end;
for i := 0 to 1 do
fallFace[i] := SATGetFace(136 + i);
end;
procedure HandlePlayerSprite (me: PlSpritePtr);
var
theEvent: EventRecord;
temp: char;
begin
HandleKeys(me);
(* Vspeed Limit ,Acceleration and Updating V Position *)
if (me^.speed.v > 30) then
me^.speed.v := 30;
me^.speed.v := me^.speed.v + Gforce;
me^.position.v := me^.position.v + me^.speed.v;
(* Keeping the Hero with the same speed as the HMov platform *)
if (me^.action = JumpFromHMov) then
me^.position.h := me^.position.h + me^.speed.h;
(*Make sure we are always visible!*)
(*************************)
if (me^.position.v < 0) then
begin
me^.position.v := 0;
me^.speed.v := 0;
end;
if (me^.position.h < 0) then
begin
me^.position.h := 0;
me^.speed.h := 0;
end;
if (me^.position.v > gSAT.offSizeV - PlayerHigh) then
begin
me^.action := Stand;
me^.position.v := gSAT.offSizeV - PlayerHigh;
me^.speed.v := 0;
end;
if (me^.position.h > gSAT.offSizeH - PlayerHigh) then
begin
me^.position.h := gSAT.offSizeH - PlayerHigh;
me^.speed.h := 0;
end;
me^.mode := abs(me^.mode + 1);
me^.layer := -(me^.position.v);
end; {HandlePlayerSprite}
procedure HitPlayerSprite (me: SpritePtr; him: SpritePtr);
begin
(* Hit something! We can take whatever action we need here, but in this case,}
{ we let the other sprites decide. We could have omitted this function altogether and passed nil.*)
if him^.kind = 1 then
begin
end
else if him^.kind = 2 then
begin
end;
end; {HitPlayerSprite}
procedure SetupPlayerSprite (me: PlSpritePtr);
begin
me^.action := Stand;
me^.mode := 0;
me^.speed.h := 0;
me^.kind := 1; (* friend kind *)
SetRect(me^.hotRect, 12, 0, PlayerHigh - 10, PlayerHigh);
me^.face := fallFace[0];
me^.task := @HandlePlayerSprite;
me^.hitTask := @HitPlayerSprite;
playerSp := me;
end; {SetupPlayerSprite}
procedure HandleKeys (me: PlSpritePtr);
{ RIGHT - Key Number 6}
begin
if (IsPressed($7B) or IsPressed($56)) then (* left *)
begin
if me^.action = JumpFromHMov then
me^.position.h := me^.position.h - PlayerSpeed - abs(me^.speed.h)
else
me^.position.h := me^.position.h - PlayerSpeed;
me^.speed.h := -PlayerSpeed;
me^.face := leftFaces[BitAnd(me^.mode div 3, 3)];
end;
{ LEFT - Key Number 4}
if (IsPressed($7C) or IsPressed($58)) then (* right *)
begin
if (me^.action = JumpFromHMov) then {stay on the platform}
me^.position.h := me^.position.h + PlayerSpeed - abs(me^.speed.h)
else
me^.position.h := me^.position.h + PlayerSpeed;
me^.speed.h := PlayerSpeed;
me^.face := rightFaces[BitAnd(me^.mode div 3, 3)]; {replace the face}
end;
{ Not JUMP - not pushing key num 8 ,to prevent auto jumping!}
if (not (IsPressed($7E) or IsPressed($5B))) then
me^.JumpKey := NotPushed;
{ JUMP - Key Number 8 }
if (IsPressed($7E) or IsPressed($5B)) then
begin
if (me^.speed.v < 10) then
begin
if ((me^.JumpKey = NotPushed) and ((me^.action <> Jump) and (me^.action <> JumpFromHMov))) then
begin
me^.speed.v := -JumpSpeed;
if (me^.action = StandOnHMovPlatform) then
begin
me^.position.h := me^.position.h + me^.speed.h;
me^.action := JumpFromHMov;
end
else
me^.action := Jump;
me^.JumpKey := Pushed;
end;
end;
end;
{ Down - Key Number 2}
if (IsPressed($7D) or IsPressed($54)) then
;
{ - Clear Key}
if (IsPressed($47)) then
;
end;
end.